//
//                                  _oo8oo_
//                                 o8888888o
//                                 88" . "88
//                                 (| -_- |)
//                                 0\  =  /0
//                               ___/'==='\___
//                             .' \\|     |// '.
//                            / \\|||  :  |||// \
//                           / _||||| -:- |||||_ \
//                          |   | \\\  -  /// |   |
//                          | \_|  ''\---/''  |_/ |
//                          \  .-\__  '-'  __/-.  /
//                        ___'. .'  /--.--\  '. .'___
//                     ."" '<  '.___\_<|>_/___.'  >' "".
//                    | | :  `- \`.:`\ _ /`:.`/ -`  : | |
//                    \  \ `-.   \_ __\ /__ _/   .-` /  /
//                =====`-.____`.___ \_____/ ___.`____.-`=====
//                                  `=---=`
//
//
//               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//                          佛祖保佑         永无bug

#import "HJTDateTool.h"
#import "HJTDateFormatter.h"
#import <YYCategories/YYCategories.h>

@implementation HJTDateTool
static NSDateFormatter *_formatter;

+ (void)initialize{
    _formatter = [[NSDateFormatter alloc]init];
}

+ (BOOL)isLargeThenOneDay:(NSInteger)curTime;
{
    return (curTime - [NSDate new].timeIntervalSince1970) > (24 *60 *60);
}

+ (BOOL)isNowYear:(NSInteger)curTime {
    NSDate *date =  [NSDate dateWithTimeIntervalSince1970:curTime];
     NSDate *curDate = [NSDate new];
    return (date.year == curDate.year);
}

+ (NSString *)dateForFormatOneWithDate:(NSDate *)date {
    [[HJTDateFormatter defaultDateFormatter] setDateFormat:@"yyyy-MM-dd"];
    return [[HJTDateFormatter defaultDateFormatter] stringFromDate:date];
}

+ (NSString *)dateForFormatOneWithTimeStamp:(NSString *)timeStamp {
    // 都是从1970开始
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[timeStamp doubleValue]];
    // 用于NSdate对象的格式化
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    // 设置格式 zzz表示时区
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    // 设置地区
    dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en"];
    // NSDate转NSString
    NSString *dateString = [dateFormatter stringFromDate:date];
    return dateString;
}

// yyyy-MM-dd
+ (NSString *)dateForFormatOneWithTimeStamp:(NSString *)timeStamp withFormat:(NSString *)format {
    // 都是从1970开始
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[timeStamp doubleValue]];
    // 用于NSdate对象的格式化
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    // 设置格式 zzz表示时区
    [dateFormatter setDateFormat:format];
    // 设置地区
    dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en"];
    // NSDate转NSString
    NSString *dateString = [dateFormatter stringFromDate:date];
    return dateString;
}

+ (NSString *)dateForFormatWithTs:(NSTimeInterval)ts withFormat:(NSString *)format {
    // 都是从1970开始
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:ts];
    // 用于NSdate对象的格式化
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    // 设置格式 zzz表示时区
    [dateFormatter setDateFormat:format];
    // 设置地区
//    dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en"];
//    dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"GMT"];
    // NSDate转NSString
    NSString *dateString = [dateFormatter stringFromDate:date];
    return dateString;
}

+ (NSString *)dateForFormatWithTimeStamp:(NSString *)timeStamp withFormat:(NSString *)format {
    // 都是从1970开始
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[timeStamp doubleValue]];
    // 用于NSdate对象的格式化
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    // 设置格式 zzz表示时区
    [dateFormatter setDateFormat:format];
    // 设置地区
    dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en"];
    dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"GMT"];
    // NSDate转NSString
    NSString *dateString = [dateFormatter stringFromDate:date];
    return dateString;
}

+ (NSString *)dateJudgeWithStartDate:(NSString *)startDate endData:(NSString *)endDate {
    [[HJTDateFormatter defaultDateFormatter] setDateFormat:@"yyyy-MM-dd"];
    
    // 当前日期
    NSString *currenDate = [[HJTDateFormatter defaultDateFormatter] stringFromDate:[NSDate dateWithTimeIntervalSinceNow:0]];
    
    if (startDate.length != 0 && endDate.length != 0) {
        if ([startDate compare:endDate] == NSOrderedDescending) {
            return NSLocalizedString(@"TimeTip1", @"结束时间不应小于开始时间");
        }
    } else if (startDate.length != 0) {
        if ([startDate compare:currenDate] == NSOrderedAscending) {
            return NSLocalizedString(@"TimeTip2", @"开始时间不应小于当前时间");
        }
    } else {
        if ([endDate compare:currenDate] == NSOrderedAscending) {
            return NSLocalizedString(@"TimeTip3", @"结束时间不应小于当前时间");
        }
    }
    
    return nil;
}

+(NSString *)translateDate:(NSString *)dateStr{
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[dateStr doubleValue]];
    //    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    //    [formatter setDateStyle:NSDateFormatterMediumStyle];
    //    [formatter setTimeStyle:NSDateFormatterShortStyle];
    //    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    return [self compareCurrentTime:confromTimesp justDate:NO];
}

+(NSString *)translateDateWithJavaTime:(NSTimeInterval)time limit:(NSInteger)limit formatter:(NSString *)formatter
{
    if (time > 9999999999) {
        time = time / 1000;
    }
    NSDate *timeDate = [NSDate dateWithTimeIntervalSince1970:time];
    
    //把字符串转为NSdate
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSDate *currentDate = [NSDate date];
    NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:timeDate];
    
    long temp = 0;
    NSString *result;
    
    if (limit <=0) {
        if (formatter.length<=0) {
            formatter = @"yyyy-MM-dd";
        }
        [dateFormatter setDateFormat:formatter];
        result = [dateFormatter stringFromDate:timeDate];
        return result;
    }
    
    if (timeInterval/60 < 1) {
        result = [NSString stringWithFormat:NSLocalizedString(@"JustNow", @"刚刚")];
    }
    else if((temp = timeInterval/60) <60){
        result = [NSString stringWithFormat:NSLocalizedString(@"SomeMinAgo", @"%d分钟前"),temp];
    }
    else if((temp = temp/60) <24){
        result = [NSString stringWithFormat:NSLocalizedString(@"SomeHoursAgo", @"%d小时前"),temp];
    }
    else if((temp = temp/24) < limit || formatter.length<=0){
        if (temp == 1) {
            result = NSLocalizedString(@"Yesterday", @"昨天");
        }else if(temp == 2){
            result = NSLocalizedString(@"BeforeDay", @"前天");
        }else{
            temp = MIN(temp, limit);
            result = [NSString stringWithFormat:NSLocalizedString(@"SomeDaysAgo", @"%ld天前"),temp];
        }
    }
    else { //显示年月日
        [dateFormatter setDateFormat:formatter];
        result = [dateFormatter stringFromDate:timeDate];
    }
    
    return result;
}

+(NSString *)translateDateWithJavaTime:(NSTimeInterval)time
{
    if (time > 9999999999) {
        time = time / 1000;
    }
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:time];
    //    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    //    [formatter setDateStyle:NSDateFormatterMediumStyle];
    //    [formatter setTimeStyle:NSDateFormatterShortStyle];
    //    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    return [self compareCurrentTime:confromTimesp justDate:NO];
}

+ (NSString *)compareCurrentTime:(NSDate *)timeDate justDate:(BOOL)jusetData{
    //把字符串转为NSdate
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    //    NSDate *timeDate = [dateFormatter dateFromString:str];
    //    NSDate *currentDate = [NSDate date];
    NSDate *currentDate = [NSDate date];
    //    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    //    NSInteger interval = [zone secondsFromGMTForDate:currentDate];
    //    currentDate = [currentDate  dateByAddingTimeInterval: interval];
    NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:timeDate];
    
    long temp = 0;
    NSString *result;
    
    if (jusetData) {
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        result = [dateFormatter stringFromDate:timeDate];
        return result;
    }
    
    if (timeInterval/60 < 1) {
        result = [NSString stringWithFormat:NSLocalizedString(@"JustNow", @"刚刚")];
    }
    else if((temp = timeInterval/60) <60){
        result = [NSString stringWithFormat:NSLocalizedString(@"SomeMinAgo", @"%d分钟前"),temp];
    }
    else if((temp = temp/60) <24){
        result = [NSString stringWithFormat:NSLocalizedString(@"SomeHoursAgo", @"%d小时前"),temp];
    }
    else if((temp = temp/24) <10){
        if (temp == 1) {
            result = NSLocalizedString(@"Yesterday", @"昨天");
        }else if(temp == 2){
            result = NSLocalizedString(@"BeforeDay", @"前天");
        }else{
            result = [NSString stringWithFormat:NSLocalizedString(@"SomeDaysAgo", @"%ld天前"),temp];
        }
    }
    else { //显示年月日
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        result = [dateFormatter stringFromDate:timeDate];
    }
    
    return result;
}

+ (NSString *)translateDateToSimpleStrWithJavaTime:(NSTimeInterval)time
{
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:time / 1000];
    //    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    //    [formatter setDateStyle:NSDateFormatterMediumStyle];
    //    [formatter setTimeStyle:NSDateFormatterShortStyle];
    //    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    return [self compareCurrentTime:confromTimesp justDate:YES];
}

+ (NSDictionary *)translateUnixTime:(NSTimeInterval)unixTime{
    if (unixTime > 9999999999) {
        unixTime = unixTime / 1000;
    }
    NSTimeInterval now = [[NSDate date]timeIntervalSince1970];
    double distanceTime = now - unixTime;
    NSString *distanceStr,*timeStr;
    
    NSDate *beDate = [NSDate dateWithTimeIntervalSince1970:unixTime];
    NSDateFormatter *df = [[NSDateFormatter alloc]init];
    [df setDateFormat:@"HH:mm"];
    timeStr = [df stringFromDate:beDate];
    
    [df setDateFormat:@"dd"];
    NSString *nowDay = [df stringFromDate:[NSDate date]];
    NSString *lastDay = [df stringFromDate:beDate];
    
    if (distanceTime < 24*60*60 && [nowDay integerValue] == [lastDay integerValue]) {
        distanceStr = NSLocalizedString(@"Today", @"今天");
        NSInteger temp = 0;
        if (distanceTime < 60) {
            timeStr = NSLocalizedString(@"JustNow", @"刚刚");
        }else if((temp = distanceTime/60) < 60){
            timeStr = [NSString stringWithFormat:NSLocalizedString(@"SomeMinAgo", @"%d分钟前"),temp];
        }else if((temp = temp/60) < 24){
            timeStr = [NSString stringWithFormat:NSLocalizedString(@"SomeHoursAgo", @"%d小时前"),temp];
        }
    }
    else if([nowDay integerValue] - 1 == [lastDay integerValue]){
        distanceStr = NSLocalizedString(@"Yesterday", @"昨天");
    }
    else if([nowDay integerValue] - 2 == [lastDay integerValue]){
        distanceStr = NSLocalizedString(@"BeforeDay", @"前天");
    }else{
        [df setDateFormat:@"yyyy-MM-dd"];
        distanceStr = [df stringFromDate:beDate];
    }
    
    return @{@"dayDis":distanceStr,@"timeDis":timeStr};
}


+(long)returnNSDateWithStandardTime:(NSString*)timeStr{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    //指定时间显示样式: HH表示24小时制 hh表示12小时制
    [formatter setDateFormat:@"YYYY/MM/dd HH:mm:ss"];
    NSString *lastTime = timeStr;
    NSDate *lastDate = [formatter dateFromString:lastTime];
    //以 1970/01/01 GMT为基准，得到lastDate的时间戳
    long firstStamp = [lastDate timeIntervalSince1970];
    return firstStamp;
}


+ (NSTimeInterval)dateIntevalWithISOFormatString:(NSString *)dateString {
    NSDate *date = [self dateWithISOFormatString:dateString];
    NSTimeInterval timeInteval = date.timeIntervalSince1970;
    return timeInteval;
}

+ (NSDate *)dateWithISOFormatString:(NSString *)dateString {
    static NSDateFormatter *formatter = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        formatter = [[NSDateFormatter alloc] init];
        formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
        formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZ";
    });
    return [formatter dateFromString:dateString];
}


+ (NSString*)currenDate{
    // 当前星期
    //    NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @"周日", @"周一", @"周二", @"周三", @"周四", @"周五", @"周六", nil];
    //    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    //    NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Shanghai"];
    //    [calendar setTimeZone: timeZone];
    //    NSCalendarUnit calendarUnit = NSCalendarUnitWeekday;
    //    NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:[NSDate date]];
    //    return [weekdays objectAtIndex:theComponents.weekday];
    
    // 当前年月日
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"yyyy-MM-dd";
    NSString *date = [fmt stringFromDate:[NSDate date]];
    return date;
}

+ (NSTimeInterval)timeSpan:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second{
    NSCalendar *greCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    
    NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Shanghai"];
    [greCalendar setTimeZone:timeZone];
    
    NSDateComponents *dateComponents = [greCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:[NSDate date]];
    
    //定义一个NSDateComponents对象，设置一个时间点
    NSDateComponents *dateComponentsForDate = [[NSDateComponents alloc] init];
    [dateComponentsForDate setDay:dateComponents.day];
    [dateComponentsForDate setMonth:dateComponents.month];
    [dateComponentsForDate setYear:dateComponents.year];
    [dateComponentsForDate setHour:hour];
    [dateComponentsForDate setMinute:minute];
    [dateComponentsForDate setSecond:second];
    
    NSDate *dateFromDateComponentsForDate = [greCalendar dateFromComponents:dateComponentsForDate];
    return [dateFromDateComponentsForDate timeIntervalSince1970];
}

+ (NSString *)formateUnixTime:(NSTimeInterval)unixTime format:(NSString *)format{
    _formatter.dateFormat = format;
    
    NSDate *date = [self dateFromUnixTime:unixTime];
    return [_formatter stringFromDate:date];
}

+ (NSDate *)dateFromUnixTime:(NSTimeInterval)unixTime{
    if (unixTime > 9999999999) {
        unixTime = unixTime / 1000;
    }
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:unixTime];
    return date;
}

+ (NSInteger)calcAge:(NSTimeInterval)birthday{
    NSDate *bornDate = [self dateFromUnixTime:birthday];
    NSDate *currentDate = [NSDate date];
    //获得当前系统时间与出生日期之间的时间间隔
    NSTimeInterval time = [currentDate timeIntervalSinceDate:bornDate];
    //时间间隔以秒作为单位,求年的话除以60*60*24*356
    NSInteger age = time/(3600*24*365);
    return age;
}

+ (NSString *)formateDateTime:(NSString *)dateTime fromFormat:(NSString *)fromFormat toFormat:(NSString *)toFormat{
    
    NSDate *date = [self formateDateTime:dateTime format:fromFormat];
    _formatter.dateFormat = toFormat;
    return [_formatter stringFromDate:date];
}

+ (NSDate *)formateDateTime:(NSString *)dateTime format:(NSString *)format{
    _formatter.dateFormat = format;
    NSDate *date = [_formatter dateFromString:dateTime];
    return date;
}

+ (NSString *)formateDate:(NSDate *)date format:(NSString *)format{
    _formatter.dateFormat = format;
    return [_formatter stringFromDate:date];
}

+ (NSArray *)getDateInternal:(TimeIntervalType)type internalDate:(NSDate *)internalDate value:(NSInteger)value format:(NSString *)format{
    if (format.length == 0) {
        format = @"yyyy-MM-dd";
    }
    
    NSCalendar *calendar = [NSCalendar currentCalendar];
    [calendar setTimeZone:[NSTimeZone localTimeZone]];
    
    NSDate *now = [NSDate date];
    NSString *nowStr = [HJTDateTool formateDate:now format:@"yyyy-MM-dd"];
    now = [HJTDateTool formateDateTime:nowStr format:@"yyyy-MM-dd"];
    
    [calendar setFirstWeekday:2];//设定周一为周首日
    switch (type) {
        case TimeIntervalTypeWeek:
        {
            NSDateComponents *comp = [calendar components: NSCalendarUnitWeekday | NSCalendarUnitWeekOfYear fromDate:now];
            // 获取是周几 (周一是2，周日是1)
            NSInteger weekDay = [comp weekday];
            
            //这周是今年的第几周(注意：第一周编号为1不为0)
            NSInteger weekOfYear = [comp weekOfYear];
            [_formatter setDateFormat:format];
            
            //这周的开始和结束时间 （注意：+1 -1 避开临界值）
            //今天是周末
            NSDate *endDate = nil;
            NSDate *startDate = nil;
            if (weekDay == 1) {
                endDate = now;
                startDate = [now dateByAddingDays:-6];
            }
            else
            {
                startDate = [now dateByAddingTimeInterval:24*3600*(2 - weekDay)+1];
                endDate = [now dateByAddingTimeInterval:24*3600*(9 - weekDay)-1];
            }
            
            NSDate *startdate1 = [startDate dateByAddingTimeInterval:24*3600*7*(value-weekOfYear)];
            NSDate *enddate1 = [endDate dateByAddingTimeInterval:24*3600*7*(value-weekOfYear)];
            
            //判断当前时间在范围内没有
            if ([now laterDate:startdate1] == now && [now earlierDate:enddate1] == now) {
                enddate1 = now;
            }
            
            NSString *startDateStr = [_formatter stringFromDate:startdate1];
            NSString *endDateStr = [_formatter stringFromDate:enddate1];
            //            NSArray * dateArr = [WKCalendarManager getMondayAndSundayWithDate:now];
            //            NSString *startDateStr = [_formatter stringFromDate:dateArr.firstObject];
            //            NSString *endDateStr = [_formatter stringFromDate:dateArr.lastObject];
            
            return [NSArray arrayWithObjects:startDateStr,endDateStr, nil];
        }
        case TimeIntervalTypeMonth:
        {
            [_formatter setDateFormat:@"yyyy"];
            NSString *dateStr = [_formatter stringFromDate:internalDate];
            dateStr = [dateStr stringByAppendingFormat:@"-%ld-01",value];
            [_formatter setDateFormat:@"yyyy-MM-dd"];
            NSDate *firstDay = [_formatter dateFromString:dateStr];
            double interval = 0;
            [calendar rangeOfUnit:NSCalendarUnitMonth startDate:&firstDay interval:&interval forDate:internalDate];
            NSDate *lastDay = [firstDay dateByAddingTimeInterval:interval-1];
            _formatter.dateFormat = format;
            
            //判断当前时间在范围内没有
            if ([now laterDate:firstDay] == now && [now earlierDate:lastDay] == now) {
                lastDay = now;
            }
            
            return [NSArray arrayWithObjects:[_formatter stringFromDate:firstDay],[_formatter stringFromDate:lastDay], nil];
        }
        case TimeIntervalTypeYear:
        {
            [_formatter setDateFormat:@"yyyy"];
            NSString *dateStr = [_formatter stringFromDate:internalDate];
            dateStr = [dateStr stringByAppendingString:@"-02-14"];
            [_formatter setDateFormat:@"yyyy-MM-dd"];
            NSDate *aDayOfFebruary = [_formatter dateFromString:dateStr];
            
            NSCalendar *calendar = [NSCalendar currentCalendar];
            NSDate *firstDay;
            [calendar rangeOfUnit:NSCalendarUnitYear startDate:&firstDay interval:nil forDate:internalDate];
            NSDateComponents *lastDateComponents = [calendar components:NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitDay fromDate:firstDay];
            NSUInteger dayNumberOfFebruary = [calendar rangeOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitMonth forDate:aDayOfFebruary].length;
            NSInteger day = [lastDateComponents day];
            [lastDateComponents setDay:day+337+dayNumberOfFebruary-1];
            NSDate *lastDay = [calendar dateFromComponents:lastDateComponents];
            _formatter.dateFormat = format;
            
            return [NSArray arrayWithObjects:[_formatter stringFromDate:firstDay],[_formatter stringFromDate:lastDay], nil];
        }
    }
}

+ (NSDate *)getMonthLastDayWith:(NSDate *)date{
    double interval = 0;
    NSDate *firstDate = nil;
    NSDate *lastDate = nil;
    NSCalendar *calendar = [NSCalendar currentCalendar];
    
    BOOL OK = [calendar rangeOfUnit:NSCalendarUnitMonth startDate:&firstDate interval:&interval forDate:date];
    if (OK) {
        lastDate = [firstDate dateByAddingTimeInterval:interval - 1];
    }else {
        return date;
    }
    return lastDate;
}

+ (NSString *)translateUnixTime:(NSTimeInterval)unixTime format:(NSString *)format{
    if (unixTime > 9999999999) {
        unixTime = unixTime / 1000;
    }
    NSTimeInterval now = [[NSDate date]timeIntervalSince1970];
    double distanceTime = now - unixTime;
    NSString *distanceStr,*timeStr;
    
    NSDate *beDate = [NSDate dateWithTimeIntervalSince1970:unixTime];
    NSDateFormatter *df = [[NSDateFormatter alloc]init];
    [df setDateFormat:format];
    timeStr = [df stringFromDate:beDate];
    
    [df setDateFormat:@"dd"];
    NSString *nowDay = [df stringFromDate:[NSDate date]];
    NSString *lastDay = [df stringFromDate:beDate];
    
    if (distanceTime < 24*60*60 && [nowDay integerValue] == [lastDay integerValue]) {
        distanceStr = NSLocalizedString(@"Today", @"今天");
    }
    else if([nowDay integerValue] - 1 == [lastDay integerValue]){
        distanceStr = NSLocalizedString(@"Yesterday", @"昨天");
    }
    else if([nowDay integerValue] - [lastDay integerValue]>1 && [nowDay integerValue] - [lastDay integerValue]<=7){
        distanceStr = @"一周内";
    }else{
        distanceStr = @"更早";
    }
    return distanceStr;
}

+ (NSDictionary *)translateUnixTimeFroDetail:(NSTimeInterval)unixTime{
    if (unixTime > 9999999999) {
        unixTime = unixTime / 1000;
    }
    NSTimeInterval now = [[NSDate date]timeIntervalSince1970];
    double distanceTime = now - unixTime;
    NSString *distanceStr,*timeStr;
    
    NSDate *beDate = [NSDate dateWithTimeIntervalSince1970:unixTime];
    NSDateFormatter *df = [[NSDateFormatter alloc]init];
    [df setDateFormat:@"HH:mm"];
    timeStr = [df stringFromDate:beDate];
    
    [df setDateFormat:@"dd"];
    NSString *nowDay = [df stringFromDate:[NSDate date]];
    NSString *lastDay = [df stringFromDate:beDate];
    
    if (distanceTime < 24*60*60 && [nowDay integerValue] == [lastDay integerValue]) {
        distanceStr = NSLocalizedString(@"Today", @"今天");
        NSDateFormatter *df = [[NSDateFormatter alloc]init];
        [df setDateFormat:@"HH:mm"];
        timeStr = [df stringFromDate:beDate];
    }
    else if([nowDay integerValue] - 1 == [lastDay integerValue]){
        distanceStr = NSLocalizedString(@"Yesterday", @"昨天");
    }
    else if([nowDay integerValue] - 2 == [lastDay integerValue]){
        distanceStr = NSLocalizedString(@"BeforeDay", @"前天");
    }else{
        [df setDateFormat:@"yyyy-MM-dd"];
        distanceStr = [df stringFromDate:beDate];
    }
    
    return @{@"dayDis":distanceStr,@"timeDis":timeStr};
}


@end
